package dianmobile.eistarandroid.ui.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import dianmobile.eistarandroid.R;
import dianmobile.eistarandroid.beans.MailEntity;

/**
 * Created by Administrator on 2015/7/21.
 */
public class OutMailListAdapter extends BaseAdapter {

    private List<MailEntity> outMailList;
    private LayoutInflater inflater;
    private MailEntity mailItem;

    public OutMailListAdapter(Context context, List<MailEntity> list) {
        outMailList = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return outMailList.size();
    }

    @Override
    public Object getItem(int position) {
        return outMailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        mailItem = outMailList.get(position);

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.listitem_out_mail, null);
            viewHolder = new ViewHolder();
            viewHolder.addresseeName = (TextView)convertView.findViewById(R.id.tv_addresseeName);
            viewHolder.outMailTitle = (TextView)convertView.findViewById(R.id.tv_out_mail_title);
            viewHolder.outSendTime = (TextView)convertView.findViewById(R.id.tv_out_sendTime);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        viewHolder.addresseeName.setText(mailItem.getUserID());
        viewHolder.outSendTime.setText(mailItem.getSendTime());
        viewHolder.outMailTitle.setText(mailItem.getMailTitle());

        return convertView;
    }

    class ViewHolder {
        TextView addresseeName;
        TextView outSendTime;
        TextView outMailTitle;
    }
}
